package br.com.vti.sisp_sicrim.antigo.util;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.design.JRDesignBand;
import net.sf.jasperreports.engine.design.JRDesignBreak;
import net.sf.jasperreports.engine.design.JRDesignExpression;
import net.sf.jasperreports.engine.design.JRDesignField;
import net.sf.jasperreports.engine.design.JRDesignSection;
import net.sf.jasperreports.engine.design.JRDesignStaticText;
import net.sf.jasperreports.engine.design.JRDesignTextField;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.type.HorizontalAlignEnum;

public class ReportDesigner {

	public JasperDesign getDesign(int pageSize) throws JRException {

		// Cria um novo relat�rio
		JasperDesign jasperDesign = new JasperDesign();
		// jasperDesign.setTitleNewPage(true);
		JRDesignBand jrDesignband;
		JRDesignStaticText staticText;
		// PAGE
		jasperDesign.setPageWidth((8 * 80) + 22); // *
		jasperDesign.setPageHeight(1000);
		jasperDesign.setColumnCount(1);
		jasperDesign.setColumnWidth(8 * 80);
		jasperDesign.setColumnSpacing(0);
		jasperDesign.setLeftMargin(10);
		jasperDesign.setRightMargin(10);
		jasperDesign.setBottomMargin(5);
		jasperDesign.setTopMargin(5);
		jasperDesign.setName("Relatorio"); // *NOME DO RELATORIO

		// Adiciona coluna unica de linhas do relatorio
		JRDesignField field = null;
		field = new JRDesignField();
		field.setName("linhaRel");
		field.setValueClass(String.class);
		jasperDesign.addField(field);
		// TITLE
		/*
		 * JRDesignStaticText staticText = new JRDesignStaticText();
		 * jrDesignband.setHeight(50); staticText.setX(10); staticText.setY(10);
		 * staticText.setWidth(450); staticText.setHeight(40);
		 * staticText.setFontName("Tahoma");
		 * staticText.setForecolor(Color.BLUE);
		 * staticText.setHorizontalAlignment(HorizontalAlignEnum.CENTER);
		 * staticText.setFontSize(24);
		 * staticText.setPdfFontName("Helvetica-Bold");
		 * staticText.setBold(true); staticText.setText("Hist�rico de Consumo");
		 * jrDesignband.addElement(staticText);
		 * jasperDesign.setTitle(jrDesignband);
		 */

		// PAGE HEADER
		jrDesignband = new JRDesignBand();
		jrDesignband.setHeight(9);
		jasperDesign.setPageHeader(jrDesignband);
		// COLUMN HEADER

		jrDesignband = new JRDesignBand();
		jrDesignband.setHeight(0);
		jasperDesign.setColumnHeader(jrDesignband);
		// Dados da referencia
		/*
		 * staticText = new JRDesignStaticText(); staticText.setX(0);
		 * staticText.setY(5); staticText.setWidth(150);
		 * staticText.setHeight(15);
		 * staticText.setHorizontalAlignment(HorizontalAlignEnum.LEFT);
		 * staticText.setText("Refer�ncia - M�s/Ano"); staticText.setBold(true);
		 * jrDesignband.addElement(staticText);
		 */

		// DETAIL
		jrDesignband = new JRDesignBand();
		jrDesignband.setHeight(12);
		// Dados da referencia
		JRDesignTextField textField = new JRDesignTextField();
		textField.setBlankWhenNull(false);
		textField.setX(0);
		textField.setY(1);
		textField.setWidth(8 * 80);
		textField.setHeight(9);
		textField.setPdfFontName("Courier");
		textField.setFontName("Courier New");
		textField.setFontSize(7);
		// Adiciona a expressao no campo
		JRDesignExpression expression = new JRDesignExpression();
		expression.setValueClass(java.lang.String.class);
		expression.setText("$F{linhaRel}");
		textField.setExpression(expression);
		jrDesignband.addElement(textField);
		JRDesignBreak pageBreak = new JRDesignBreak();
		pageBreak.setX(0);
		pageBreak.setY(0);
		pageBreak.setWidth(0);
		pageBreak.setHeight(0);
		JRDesignExpression pageexpr = new JRDesignExpression();
		pageexpr.setValueClass(java.lang.Boolean.class);
		pageexpr.setText("( $V{REPORT_COUNT} - 1 ) % " + String.valueOf(pageSize) + " == 0");
		pageBreak.setPrintWhenExpression(pageexpr);
		jrDesignband.addElement(pageBreak);
                ((JRDesignSection)jasperDesign.getDetailSection()).addBand(jrDesignband);
		// COLUMN FOOTER (Escondido)
		jrDesignband = new JRDesignBand();
		jrDesignband.setHeight(0);
		jasperDesign.setColumnFooter(jrDesignband);
		// PAGE FOOTER (Escondido)
		jrDesignband = new JRDesignBand();
		jrDesignband.setHeight(0);
		jasperDesign.setPageFooter(jrDesignband);
		// NO DATA (No JasperViewer nao mostra)
		jrDesignband = new JRDesignBand();
		jrDesignband.setHeight(12);
		staticText = new JRDesignStaticText();
		staticText.setX(10);
		staticText.setY(1);
		staticText.setWidth(64);
		staticText.setHeight(9);
		staticText.setText("Sem registros para compor o relat�rio!");
		staticText.setHorizontalAlignment(HorizontalAlignEnum.CENTER);
		jrDesignband.addElement(staticText);
		jasperDesign.setNoData(jrDesignband);
		// SUMMARY (Escondido)
		jrDesignband = new JRDesignBand();
		jrDesignband.setHeight(0);
		jasperDesign.setSummary(jrDesignband);
		return jasperDesign;
	}
}